package cn.wen.yaling.controller;

import java.util.List;

import cn.wen.yaling.aop.annotation.operation.OperationLogger;
import cn.wen.yaling.commons.vo.*;
import cn.wen.yaling.xo.service.TypeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.wen.yaling.xo.service.ImageService;
import cn.wen.yaling.commons.utils.ResultEntity;



/**
 * 
 *
 * @author FY
 * @email 932043654@qq.com
 * @date 2022-08-13 02:07:37
 */
@RestController
public class ImageController {

    @Autowired
    private ImageService imageService;

    @Autowired
    private TypeService typeService;

    /**
     * 获取图片分类的列表
     * @return
     */
    @ApiOperation(value = "获取图像分类列表", notes = "获取图像分类列表", response = ResultEntity.class)
    @GetMapping("/admin/type/image/list")
    public ResultEntity getImageTypeList() {
        return typeService.getImageTypeListBySort();
    }

    /**
     * 获取图片分类的列表
     * @return
     */
    @ApiOperation(value = "获取图像列表", notes = "获取图像列表", response = ResultEntity.class)
    @GetMapping("/admin/image/list")
    public ResultEntity getImageListByTypeId(@RequestParam("typeId") Integer typeId) {
        return imageService.getImageListByTypeId(typeId);
    }

    /**
     * 添加图片分类的列表
     * @return
     */
    @OperationLogger("添加图像")
    @ApiOperation(value = "添加图像", notes = "添加图像", response = ResultEntity.class)
    @PostMapping("/admin/image/add")
    public ResultEntity addImage(@RequestBody ImageAddVO imageAddVO) {
        return imageService.addImage(imageAddVO);
    }

    /**
     * 修改图片分类的列表
     * @return
     */
    @OperationLogger("修改图像")
    @ApiOperation(value = "修改图像", notes = "修改图像", response = ResultEntity.class)
    @PostMapping("/admin/image/update")
    public ResultEntity updateImage(@RequestBody ImageUpdateVO imageUpdateVO) {
        return imageService.updateImage(imageUpdateVO);
    }

    /**
     * 修改图片分类的列表
     * @return
     */
    @OperationLogger("删除图像操作")
    @ApiOperation(value = "删除图像", notes = "删除图像", response = ResultEntity.class)
    @PostMapping("/admin/image/delete")
    public ResultEntity deleteImage(@RequestParam("imageIds") List<Integer> imageIds) {
        return imageService.deleteBatchImageByIds(imageIds);
    }



}
